<?php

class BedrijfFormStep1 extends Form
{
	const L_FIELD_REQUIRED = 'Dit veld is verplicht';

	public function __construct( $data = array() )
	{
		parent::__construct( );
		
		if( isset( $data['id'] ) )
		{
			$this->addChild( new InputHidden( 'id', $data['id'] ) );
		}
		
		$algemeen = new FieldSet( 'Algemene gegevens' );
		
		$name = new InputText( 'name', Bedrijf::getField('name'), isset( $data[ 'name' ] ) ? $data[ 'name' ] : '', 'name' );
		$name->getValidator()->required( self::L_FIELD_REQUIRED );
		$algemeen->addChild( $name );
		
		$straat = new InputText( 'billing_address_street', Bedrijf::getField('billing_address_street'), isset( $data[ 'billing_address_street' ] ) ? $data[ 'billing_address_street' ] : '', 'street' );
		$straat->getValidator()->required( self::L_FIELD_REQUIRED );
		$algemeen->addChild( $straat );
		
		$postal = new InputText( 'billing_address_postalcode', Bedrijf::getField('billing_address_postalcode'), isset( $data[ 'billing_address_postalcode' ] ) ? $data[ 'billing_address_postalcode' ] : '', 'postal' );
		$postal->getValidator()->required( self::L_FIELD_REQUIRED );
		$postal->getValidator()->compareMatch('^([1-9]{1}[0-9]{3})[[:space:]]*([a-zA-Z]{2})$', 'U moet een geldige postcode invullen.');
		$algemeen->addChild( $postal );
		
		$city = new InputText( 'billing_address_city', Bedrijf::getField('billing_address_city'), isset( $data[ 'billing_address_city' ] ) ? $data[ 'billing_address_city' ] : '', 'city' );
		$city->getValidator()->required( self::L_FIELD_REQUIRED );
		$algemeen->addChild( $city );
		
		$country = new InputText( 'billing_address_country', Bedrijf::getField('billing_address_country'), isset( $data[ 'billing_address_country' ] ) ? $data[ 'billing_address_country' ] : '', 'street' );
		$country->getValidator()->required( self::L_FIELD_REQUIRED );
		$algemeen->addChild( $country );
		
		
		$this->addChild( $algemeen );
		
		$adresgegevens = new FieldSet( 'Bezoekadres' );
		
		$straat = new InputText( 'shipping_address_street', Bedrijf::getField('shipping_address_street'), isset( $data[ 'shipping_address_street' ] ) ? $data[ 'shipping_address_street' ] : '', 'street' );
		//$straat->getValidator()->required( self::L_FIELD_REQUIRED );
		$adresgegevens->addChild( $straat );
		
		$postal = new InputText( 'shipping_address_postalcode', Bedrijf::getField('shipping_address_postalcode'), isset( $data[ 'shipping_address_postalcode' ] ) ? $data[ 'shipping_address_postalcode' ] : '', 'postal' );
		//$postal->getValidator()->required( self::L_FIELD_REQUIRED );
		$postal->getValidator()->compareMatch('^([1-9]{1}[0-9]{3})[[:space:]]*([a-zA-Z]{2})$', 'U moet een geldige postcode invullen.');
		$adresgegevens->addChild( $postal );
		
		$city = new InputText( 'shipping_address_city', Bedrijf::getField('shipping_address_city'), isset( $data[ 'shipping_address_city' ] ) ? $data[ 'shipping_address_city' ] : '', 'city' );
		//$city->getValidator()->required( self::L_FIELD_REQUIRED );
		$adresgegevens->addChild( $city );
		
		$country = new InputText( 'shipping_address_country', Bedrijf::getField('shipping_address_country'), isset( $data[ 'shipping_address_country' ] ) ? $data[ 'shipping_address_country' ] : '', 'street' );
		//$country->getValidator()->required( self::L_FIELD_REQUIRED );
		$adresgegevens->addChild( $country );
		
		$this->addChild( $adresgegevens );
		
		$this->addChild( new SubmitButton( 'submit', 'Volgende stap' ) );
	}
}
